var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
import moment from "../../utils/moment.js";
const app = getApp()
Page({
    data: {
        tabs: ["待付款", "待收货", "代发货", "完成"],
        goods: [],
        status: {
            1: '完成',
            2: '待付款',
            3: '代发货',
            4: '待收货'
        }
    },
    onLoad: function() {
        this.getOrderList();
    },
    getOrderList() {
        const db = wx.cloud.database()
        //获取商品列表
        db.collection('order_list').where({
            buyer: app.globalData.openid,
        }).get({
            success: res => {
                console.log(res.data)
                let data = this.formatData(res.data)
                this.setData({
                    goods: data
                })
            },
            fail: err => {
                wx.showToast({
                    icon: 'none',
                    title: '查询记录失败'
                })
                console.error('[数据库] [查询记录] 失败：', err)
            }
        })
    },
    formatData(data) {
        data.forEach(item => {
            let tmpStatus = item.status;
            item.status = {};
            item.status.style = "status-" + tmpStatus;
            item.status.name = this.data.status[tmpStatus];
            item.complete_time = moment(item.complete_time).format("YYYY-MM-DD HH:mm:ss")
            item.consignee_time = moment(item.consignee_time).format("YYYY-MM-DD HH:mm:ss")
            item.order_time = moment(item.order_time).format("YYYY-MM-DD HH:mm:ss")
            item.pay_time = moment(item.pay_time).format("YYYY-MM-DD HH:mm:ss")
        })
        return data
    }
});